package Jdbc;
import java.sql.*;
public class DBUtil {
    public static final  String DRIVER="com.mysql.cj.jdbc.Driver";
    public static final  String URL="jdbc:mysql://localhost:3306/s-name?useSSL=false&useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&allowMultiQueries=true";
    public static final  String USER="root";
    public static final  String PASS="123456";
    private DBUtil(){

    }
    static {
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static Connection getConnection(){
        try {
            return  DriverManager.getConnection(URL, USER, PASS);
        } catch (SQLException e) {
            e.printStackTrace();//log4j
            throw new RuntimeException(e);
        }
    }
    public static void close(Connection con,Statement st,ResultSet rs){
        close(rs);
        close(st);
        close(con);
    }
    public static void close(Connection con){
        if(con!=null) {
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    public static void close(Statement st){
        if(st!=null) {
            try {
                st.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    public static void close(ResultSet rs){
        if(rs!=null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}